const Service = require('egg').Service;

class redisService extends Service {
    get Redis(){
        return this.app.redis;
    }
    async redistest() {
       await this.Redis.set('name','zhangsan')
    }

    async createHotc(videoid,crynum){
        const data = await this.Redis.zscore('hotvideos',videoid)
        if(data){
            //如果该记录存在 则添加相对应得分数
            await this.Redis.zincrby('hotvideos',crynum,videoid)
        }else{
             //如果该记录不存在 则创建新的字段
             await this.Redis.zadd('hotvideos',crynum,videoid)
        }
    }

    async getTopHots(){
        const data = await this.Redis.zrevrange('hotvideos',0,-1,'WITHSCORES')
        return data
    }

    
}

module.exports = redisService;